package com.longcai.piaojia.util;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

/**
 * Created by 马长鸣 on 2016/5/9.
 */
public class UtilPermission {

    public static void Permission(Activity acitivty, String[] permission){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            for(int i=0;i<permission.length;i++){

                if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(acitivty, permission[i])) {

                    if (ContextCompat.checkSelfPermission(acitivty, permission[i]) == PackageManager.PERMISSION_GRANTED) {

                        if (ActivityCompat.shouldShowRequestPermissionRationale(acitivty, permission[i])) {

                            return;

                        }

                    }

                }

            }

            ActivityCompat.requestPermissions(acitivty, permission, 0);

        }

    }

}
